package com.tianqu.tms.www.car.action;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.entity.Member;

/**
 * 入库单打印 - action
 * @author mufeiyu
 *
 */
public class CarSearchInnerInfoPrintAjaxAction extends TmsAjaxAction {
	private Logger logger = Logger.getLogger(CarSearchInnerInfoPrintAjaxAction.class);

	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		//车辆编号
		String serial = request.getParameter("serial");
		//车辆名称
		String carName = request.getParameter("carName");
		//车牌号码
		String licensePlate = request.getParameter("licensePlate");
		//车辆颜色
		String color = request.getParameter("color");
		//车架号
		String vin = request.getParameter("vin");
		try {
			carName = URLDecoder.decode(carName,"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		try {
			licensePlate = URLDecoder.decode(licensePlate,"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			color = URLDecoder.decode(color,"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		Car car = new Car();
		Member member = new Member();
		car = car.findMemberId(serial);
		member= member.getMember(String.valueOf(car.getMemberId()));
		//商户名称
		String memberRealName = member.getRealName();
		//签发日期
		String issuingDate = DateUtil.getCurrentTimeStr1();

		String background = "<img class='jp-paper-background' src='style/images/menuRK.jpg'  style='WIDTH:793px; HEIGHT:561px'/>";

		// 拼select
		StringBuffer str = new StringBuffer();
		str.append(""
						+ ""+background+""
						+ "<div class='jp-label jp-comp-806'>" + memberRealName + "</div>" 
						+ "<div class='jp-label jp-comp-807'>" + carName + "</div>"
						+ "<div class='jp-label jp-comp-808'>" + licensePlate + "</div>"
						+ "<div class='jp-label jp-comp-809'>" + color + "</div>"
						+ "<div class='jp-label jp-comp-810'>" + vin + "</div>"					
						+ "<div class='jp-label jp-comp-811'>" + issuingDate
						+ "</div>");
		String responseText1 = str.toString();
		str.append("##");
		str.append("1");
		str.append("##");
		str.append(serial);		
		
		String responseText = str.toString();
		
		uc.setAttribute("printText", responseText1);
		uc.setAttribute("soldOurPrintFlag", "1");
		uc.setAttribute("innerSoldFlag", "2");

		responseValues(response, responseText, TEXT);
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
}